<%--
  Created by IntelliJ IDEA.
  User: leixiaolong
  Date: 2018/9/13
  Time: 下午6:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="/static/css/rpt-condition.css" media="all" type="text/css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/layui/css/layui.css" media="all"
          type="text/css">
    <style>
        .layui-table-header {
            background-color: #1E9FFF;
        }

        .layui-table thead tr {
            background-color: #1E9FFF;
            color: black;
        }
    </style>
</head>
<body>
<div style="padding: 10px;">
    <div class="layui-form" style="border-color: black; border-style: solid; border-width: 1px;" lay-filter="select-condition">
        <div style="height: 20%; margin-top: 15px;">
            <div>
                <div>
                </div>
            </div>
        </div>
        <div style="float: right; margin-right: 6%; margin-top: -50px;">
            <button class="layui-btn layui-btn-normal layui-btn-radius" lay-submit data-type="search">搜索</button>
            <button class="layui-btn layui-btn-warm layui-btn-radius" style="margin-right: 20px;">重置</button>
        </div>
        <div style="clear:both"></div>
    </div>

    <div class="layui-btn-group" style="float: right; margin-right: 100px; margin-top: 5px;">
        <button class="layui-btn layui-btn-sm layui-btn-primary" lay-submit lay-filter="btn-add-filt">新增</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary">导出</button>
    </div>

    <div style=" background-color: white; margin-top: 35px;">
        <table class="layui-hide" id="tab_goods_apply" lay-filter="goods-table-filter"></table>
    </div>
</div>
</body>
</html>

<script type="text/html" id="goodsEdit">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script language='javascript' src="${pageContext.request.contextPath}/plugins/layui/layui.js"></script>
<script language='javascript' src="${pageContext.request.contextPath}/static/js/component/form-select.js"></script>
<script language='javascript' src="${pageContext.request.contextPath}/static/js/component/form-date.js"></script>
<script language='javascript' src="${pageContext.request.contextPath}/static/js/utils/moment.js"></script>

<script>
    layui.use(["form", "element", "jquery", "layer", "laydate", "table"], function () {
        var form = layui.form, element = layui.element, layer = layui.layer, $ = layui.jquery;
        var table = layui.table;


        var tableIns = table.render({
            elem: '#tab_goods_apply',
            url: '/sys/getGoodsInfoList',
            height: 'full-230',
            cols: [[
                {field: 'id', title: '商品信息id', type: 'numbers', align: 'center'},
                // {field: 'id', title: '商品信息id', align: 'center', hide:true},
                {field: 'goodsCode', title: '商品编码', align: 'center'},
                {field: 'goodsName', title: '商品名称', align: 'center'},
                {field: 'varietyCode', title: '品种编码', align: 'center', hide:true},
                {field: 'standardCode', title: '规格编码', align: 'center', hide:true},
                {field: 'unitCode', title: '单位编码', align: 'center', hide:true},
                {field: 'varietyName', title: '品种名称', align: 'center'},
                {field: 'standardName', title: '规格名称', align: 'center'},
                {field: 'unit', title: '单位', align: 'center'},
                {field: 'taxRate', title: '税率', align: 'center'},
                {field: 'statName', title: '是否启用', align: 'center'},
                {
                    field: 'opertaor', title: '操作', align: 'center', templet: '#goodsEdit', fixed: 'right'
                }
            ]],
            done: function () {
                var myDate = new Date();
                layer.msg("数据渲染完成, date:" + myDate.getSeconds());
            },
            page: true
        });

        table.on('tool(goods-table-filter)', function(obj){
            var rowdata=obj.data;  //获取当前行数据
            var layEvent = obj.event;   //获取事件名称
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if(layEvent == 'edit'){
                layer.open({
                    id: 'edit-form',
                    type: 2,
                    title: ['商品信息修改', 'text-align: center; font-size: 20px;'],
                    area: ['600px', '400px'],
                    offset: 'auto',
                    content: '/base/goods_info_update',
                    success: function(){
                        var iframeId = document.getElementById('edit-form').getElementsByTagName('iframe')[0].id;
                        $('#'+ iframeId)[0].contentWindow.init(rowdata);
                    }
                });

            }else if(layEvent == 'del'){
                var param = {id: rowdata.id };
                layer.confirm("是否删除本条记录", {icon: 3}, function (index) {
                    $.ajax({
                        type: 'POST',
                        url: '/sys/goodsInfoDel',
                        data: param,
                        success: function(data){
                            layer.msg("商品信息删除成功！");
                        },
                        fail: function(data){
                            layer.msg("商品信息删除失败：" + data.data.rspMsg);
                        }
                    });
                    layer.close(index);
                });
            }
        });

        form.on('submit(btn-add-filt)', function () {
            layer.msg("打开新增页面");
            layer.open({
                type: 2,
                title: ['商品信息录入', 'text-align: center; font-size: 20px;'],
                area: ['600px', '400px'],
                offset: 'auto',
                content: '/base/goods_info_add',
            });
        });

        var actives = {
            search: function(){
                tableIns.reload({
                    where: {
                    }
                });
            },
            reset: function(){
                layer.msg("reset runing");
            },
            add:function () {
                layer.msg("打开新增页面");
                layer.open({
                    type: 2,
                    title: ['商品信息录入', 'text-align: center; font-size: 20px;'],
                    area: ['600px', '400px'],
                    offset: 'auto',
                    content: '/base/goods_info_add',
                });
            }
        };

        form.on('submit', function(data){
            actives[$(this).data("type")].call(this);
        });

    });

</script>
